package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_BODY;
import static xj.model.uml.UMLModelConstants.ATTR_LANG;
import static xj.model.uml.UMLModelConstants.ATTR_TYPE;

public class Expression extends BasicModelElement {

  public Expression() {
    this(null, null);
  }

  public Expression(String body) {
    this(null, body);
  }

  public Expression(String lang, String body) {
    setLang(lang);
    setBody(body);

    destructable = false;
    preserved = true;
  }

  public String getLang() {
    return lang;
  }

  public void setLang(String lang) {
    this.lang = lang;
    setAttribute(ATTR_LANG, lang);
  }

  public String getBody() {
    return body;
  }

  public void setBody(String body) {
    this.body = body;
    setAttribute(ATTR_BODY, body);
  }

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
    setAttribute(ATTR_TYPE, type);
  }

  @Override
  public String toString() {
    return body;
  }

  @Override
  protected boolean asElement(String attrName) {
    if (attrName != null) {
      return (attrName.equals(ATTR_BODY) ||
	      attrName.equals(ATTR_TYPE));
    }
    return false;
  }

  @Override
  protected boolean inCDATASection(String name) {
    return asElement(name);
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    Expression a = (Expression) super.clone();
    a.setLang(lang);
    a.setType(type);
    a.setBody(body);
    return a;
  }

  protected String lang;

  protected String body;

  protected String type;

}
